//导入路由信息
//https://router.vuejs.org/zh/guide/
import VueRouter  from "vue-router";
import Vue from "vue";
import HelloWorld  from "@/components/HelloWorld";
import Login from "@/components/Login";
//安装插件
Vue.use(VueRouter)
//创建VueRouter对象
const routes=[
    {
        path: '/',
        name:'index',
        //重定向
        redirect: {
            name: 'Login'
        },
    },
    {
        path: '/hello',
        name:'hello',
        component: HelloWorld,
        children: [],
    },
    {
        path: '/login',
        name:'Login',
        component: Login
        //直接引入页面
        //component: () => import('@/components/Login'),
    },
    //动态路由; :code为动态值,可传递到页面
    {
        path: '/demo/:code',
        component: () => import('@/components/demo')
    },
    {
        path: '/demo/:code/admin/:name',
        component: () => import('@/components/demo')
    },
]



//创建 router 实例，然后传 `routes` 配置
const router =  new VueRouter({
    //配置路由和组件之间的应用关系
    routes //缩写,相当于 routes: routes
})



//路由守卫,路径访问前拦截; (to : 目标路由,from : 跳转前的路由,next : 放行)
// router.beforeEach((to, from,next) => {
//     console.log(to)
//    if (to.name !== 'Login'){
//        next({name: 'Login'})
//    }else{
//         next();
//    }
// })

export default router;